
<template>
  <div class='groupHead' >
      <el-row class='first-title'>
        <div class="lf groupTitle">
            <div >
                <h3 class="">员工名册<small class="sub-title">{{returnValue.shortName || '总部机构'}}</small><span class="TotalSum">共{{totalNum||0}}人</span></h3>
            </div>
        </div>
        <search-box @getValue="getSearchText" :text="text"></search-box>
      </el-row>
      <!--<el-row class="second-sec">
          <div class="display-title">
            <el-radio-group v-model="radio3" @change="handleRadioChange" fill="#449d44" text-color="#fff">
              <el-radio-button label="员工名片">员工名片</el-radio-button>
              <el-radio-button label="员工列表" >员工列表</el-radio-button>
            </el-radio-group>
          </div>

      </el-row>-->

      <el-row class="second-sec">
          <div class="containerCard"  >
             
                <div class="unitContainer" >
                    <transition name="slide-fade">
                      <div class="card-body">
                        <card-leader width="50%" v-for='item in cardList' :personInfo='item' :key="item.id" type="group"></card-leader>
                      </div>
                    </transition>

                </div>   
            
       
          </div>

      </el-row>
  </div>
</template>

<script>
//   import 'Mock/mock_data'
  import Vue from 'vue'
  import {Input, Col, Row} from 'element-ui' 
  Vue.use(Input)
  Vue.use(Col)
  Vue.use(Row)



  import cardLeader from '@/components/public/card-memeber'
  import searchBox from '@/components/public/search-box'
//   import searchCol from '@/components/public/selectShowCol'
    export default {
      data() {
        return {

          text:'请输入姓名、拼音、员工编号搜索',
          searchText:'',
          deptDescr:null,
          deplid:null,
          setid:null,
          isLoadEnd:false,
          totalNum:0,
          cardList:[],
          searchRecord:false,
          showCard:true,
          cardPageSize:30,
          cardPageNum:1,
          currentPage:1,
        }
      },
      methods: {
        clearData:function(){
            // this.searchRecord = false;
            this.isLoadEnd = false;
            this.cardList = [];
            this.unitTableList = [];
            this.cardPageNum = 1;
            this.currentPage=1;

        },

        getSearchText:function(text){
          var self =this;
          if (!text.trim()) {
            //   this.cardList = [];
            //   this.totalNum = 0;
            //   this.cardPageNum = 1;
              this.clearData();
              this.searchRecord = false;
              this.selectAjax();
              return;
          }
          this.searchText = text;
          this.cardPageNum = 1;
          this.searchRecord = true;
          this.cardList = [];
          var params = {
            search:this.searchText,
            pageSize:30,
            pageNum:1,
          }
          this.PostAjax(this.URL.getEmployeeByListSearch.url,params,3);
        },
        handleRowClass:function(row, index){
          return index%2 === 0 ? 'even-row' : 'odd-row';
        },
        selectAjax:function(){

            if (this.searchRecord) {
                var params = {
                    search:this.searchText,
                    pageSize:this.cardPageSize,
                    pageNum:this.currentPage
                }
                this.PostAjax(this.URL.getEmployeeByListSearch.url,params,3);    
            } else {
                this.getLeaderListCommonAjax()
            }


        },



        getLeaderSecList:function(value){
          var self =this;
          if (value === "全部") {
            value="";
            this.clearData();
          }
          this.clearData();
          this.leaderSec = value;
          var type;
          if (value) { type="1";}   
          this.getLeaderListCommonAjax(type);
        },
        collpseCard:function(unit){
          unit.show =  unit.show ? false : true; 
        },
        getLeaderListCommonAjax:function(type){
            var self = this;
            var params = type === 2 ?            
                  {
                    setid:this.returnValue.setid || "",
                    selectname:this.searchText,
                    deplid:this.returnValue.deptid || "",
                    type:2,
                    pageSize:this.pageSizeTable ,
                    pageNum:this.currentPage
                  }
                  :
                  {
                    setid:this.returnValue.setid || "",
                    selectname:this.searchText,
                    deplid:this.returnValue.deptid || "",
                    type:2,
                    pageSize:this.cardPageSize,
                    pageNum:this.cardPageNum
                  } ; 
                  this.PostAjax(this.URL.getEmployeeByList.url,params,type);
        },
        PostAjax:function(url,params,type){
            var self = this;
            if (type === 3) {
                this.searchRecord = true;
            } else {
                this.searchRecord = false;
            }
            this.Axios.Post(url,params).then(function(res){
  
                self.totalNum = res.data.page ? res.data.page.total : res.data.total;

                var arr1 = JSON.parse(JSON.stringify(res.data.datas));
                if (type===2) {
                    
                    self.unitTableList = JSON.parse(JSON.stringify(arr1.depempList));
                    self.totalTableNum = self.unitTableList.length;
                } else {
                    if (self.searchRecord) {

		                		var arr1 = arr1.depempList;
		                		self.cardList = self.cardList.concat(arr1);
		                    if (self.cardList.length === self.totalNum) {

		                        self.isLoadEnd = true;
		                    }
                    } else {  
                        if(arr1 && arr1.depempList){
                            self.cardList = self.cardList.concat(arr1.depempList);
                        }
                        if (self.cardList.length === self.totalNum) {
                            self.isLoadEnd = true;
                        }
                    }
                   
                }               
            })
        },

        scrollFunc:function(event) {
            var self = this;
            if (this.isLoadEnd) {
                return;
            }
            var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; 
            if(document.documentElement.scrollHeight - (document.documentElement.clientHeight + scrollTop) == 0 ) {
                self.searchRecord ? self.currentPage++ : self.cardPageNum++;
                self.selectAjax();
                // self.getLeaderListCommonAjax();
            }    
        }
      },
      props:["returnValue"],
      computed:{
      },
      created:function(){

      },
      watch:{
        returnValue:function(newVal,oldVal){
          console.log('returnValue');
           this.clearData();
           this.getLeaderListCommonAjax();
        }
      },
      mounted: function () {
        var self = this;

        this.getLeaderListCommonAjax();
        window.addEventListener("scroll",this.scrollFunc);
      },
      beforeDestroy: function () {
           window.removeEventListener("scroll",this.scrollFunc);
      },
      components: {
          cardLeader,
          searchBox
      
      },
      filters:{

        },
    }

</script>

<style scoped> 
      .groupHead .first-title h3{
          font-size: 24px;
          margin-top: 20px;
          margin-bottom: 20px;
          font-weight: 500;
          line-height: 1.1;
      }
      .groupTitle{
          width: calc(100% - 249px); 
          overflow: hidden; 
      }
     .groupHead .first-title h3 small{
        font-size: 65%;
        font-weight: normal;
        line-height: 1;
        color: #777;
        margin-left:5px;
      }
      .groupHead .second-sec{
          position: relative;
          border-radius: 3px;
          min-height: 526px;
          background: #ffffff;
          border-top: 3px solid #3c8dbc;
          margin-bottom: 20px;
          width: 100%;
          box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
          border-top-color: #3c8dbc;
      }
      .content-right{
        float:right;
        margin-top:17px;
      }
      .groupHead .TotalSum{
          color:#3c8dbc;
          font-size:16px;
          margin-left:3px;
      }
      .groupHead .resumePeo{
        color:#00acd6;
        cursor: pointer;
      }
      .groupHead .select-dept{
        font-size: 14px;
      }
      .groupHead .display-title{
        border-bottom: 1px solid #f4f4f4;
        padding:10px;
      }
      .groupHead .switch-btn{
        padding: 10px 10px;
      }
      .groupHead .collapse-card{
        position:relative;
        padding: 10px 10px;
        border-bottom: 1px solid #f4f4f4;
      }

      .groupHead .table-container{
          position: relative;
          border-radius: 3px;
          background: #ffffff;
          border-top: 3px solid #d2d6de;
          margin-bottom: 20px;
          width: 100%;
          box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
          border-top-color: #00a65a;
          background-color:#fff;
      }
      .groupHead .unitContainer{
          position: relative;
          margin-bottom: 20px;
          width: 100%;

          overflow: hidden;
          clear: both;
      }
      .groupHead .third-card .collapse-card .box-title{
          display: inline-block;
          font-size: 18px;
          color: #444;
          font-weight: 500;
          margin: 0;
          line-height: 1;
      }
      .groupHead .third-card .collapse-card .collapse-container {
          position: absolute;
          right: 10px;
          top: 10px;
          cursor:pointer;
      }
      .groupHead .third-card .collapse-card  .collapse {
          border-radius: 3px;
          -webkit-box-shadow: none;
          box-shadow: none;
          border: 0px;
          padding: 5px;
          font-size: 12px;
          background: transparent;
          color: #97a0b3;
      }
      .totalNum{
          font-size: 14px;
          line-height: 1.42857143;
          color: #333;
      }


    .demo-table-expand {
      font-size: 0;
    }
    .demo-table-expand label {
      width: 90px;
      color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
      margin-right: 0;
      margin-bottom: 0;
      width: 100%;
    }



  /*选项icon样式*/
    .groupHead .handle-table{
      /*overflow: hidden;*/
      clear: both;
      padding:20px 20px 30px 20px;
      border-bottom: 1px solid #dfe6ec;
    }
    .groupHead .selectSet{
      font-size: 14px;
      font-weight: normal;
      line-height: 1.42857143;
      text-align: center;
      white-space: nowrap;
      clear: both;
      position: relative;
    }
    .groupHead .selectSet .default{
      float: left;
      background-color: #f4f4f4;
      color: #444;
      padding: 6px 12px;
      border: 1px solid #ddd;
      border-radius: 3px;
      position: relative;
      z-index:1;
    }
    .groupHead .selectSet .alt{
        margin-right:-1px;
        
    }
    .groupHead .selectSet a:hover{
      z-index:4;  
      color: #333;
      background-color: #e6e6e6;
      border-color: #adadad;
    }
    .groupHead .selectSet .alt{
        margin-right:-1px;
    }

    .selectSet .default:first-child:not(:last-child){
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        
    }
    .selectSet .default:last-child:not(:first-child) {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }

    .groupHead .downloadTable{
      padding: 7px 12px;
      margin-bottom: 0;
      font-size: 14px;
      font-weight: normal;
      line-height: 1.42857143;
      text-align: center;
      white-space: nowrap;
      background-color: #00acd6;
      border-color: #269abc;
      color: #fff;
      border-radius: 3px;
      display:inline-block;
    }
    .groupHead .downloadTable:hover{
      background-color: #3c8dbc;
      border-color: #00acd6;
    }
    
    .caret {
      display: inline-block;
      width: 0;
      height: 0;
      margin-left: 2px;
      vertical-align: middle;
      border-top: 4px dashed;
      border-top: 4px solid \9;
      border-right: 4px solid transparent;
      border-left: 4px solid transparent;
  }



    /* 可以设置不同的进入和离开动画 */
  /* 设置持续时间和动画函数 */
  .slide-fade-enter-active {
    transition: all .2s ease;
  }
  .slide-fade-leave-active {
    transition: all .4s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  }
  .slide-fade-enter, .slide-fade-leave-to
  /* .slide-fade-leave-active for below version 2.1.8 */ {
    transform: translateY(-10px);
    opacity: 0;
  }
  .groupHead .displayShow{
    display:inline-block;
    height:32px;
  }
  .groupHead .block{
    margin:15px 5px;
    line-height:32px;
  }    

</style>
<style>
    /*修改element-ui样式*/

  .groupHead .el-radio-button__inner:hover {
      color: #333;
  }
  .groupHead .el-radio-group .el-radio-button__inner:hover{
      background-color:#e7e7e7;
  }
  .groupHead .el-radio-group .el-radio-button__inner{
      background-color: #f4f4f4;
  }

  .groupHead .el-radio-group .is-active .el-radio-button__inner:hover{ 
        background-color: #d4d4d4 !important;
  }
  .groupHead .el-table th.gutter{
      display: none;
  }
  .groupHead .el-table th{
      white-space: nowrap;
      background-color: #fff;
      text-align: left;
  }
  .groupHead .el-table__header-wrapper thead div {
      background-color: #fff;
  }
  .groupHead .el-table__header-wrapper thead th>div.cell{
      padding-left: 0px;
      padding-right: 0px;
      text-align:center;
  }
  .groupHead .el-table__body-wrapper tr.el-table__row div.cell{
      padding-left: 0px;
      padding-right: 0px;
      text-align:center;
  }
  .groupHead .el-table{
    border:none;
  }
  .groupHead .el-table__body-wrapper table.el-table__body{
    width:100% !important;
    table-layout: auto;
  }
  .groupHead .el-table__header-wrapper .el-table__header{
    width:100% !important;
    table-layout: auto;
  }

  .groupHead .el-table .cell, .el-table th>div {
      padding-left: 0px;
      padding-right: 0px;
  }
  .groupHead .el-form--inline .el-form-item__label {
    width: 150px;
    float: none;
    display: inline-block;
  }
  .groupHead .el-pagination{
    display:inline-block;
  }
  .groupHead .el-table  tr td.width90, .groupHead .el-table  tr th.width90{
      min-width: 100px;
  }
  .groupHead .el-table  tr td.width40, .groupManage .el-table  tr th.width40{
      width: 40px;
  }
  .groupHead .el-table__empty-block{
    width:100% !important;
  }
</style>
